﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.User.Entity;
using PowerCreator.LMS.Web.User;

public partial class sysadmin_UserManager_AddDuty : PowerCreator.LMS.Web.Base.WebBasePage
{
    Duty opDuty = new Duty();
    private PowerCreator.LMS.Web.DL.User.LoginEntity login = new PowerCreator.LMS.Web.DL.User.LoginEntity();
    private string url = "../login.aspx";

    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!IsLicensed(PowerCreator.LMS.Action.Core.ActionInfo.AddDuty))
        //{
        //    Script.RedirectURL(GetRefUrl());
        //}

        CheckUser();
        if (!IsPostBack)
        {
            InitPage();
        }
    }

    private void CheckUser()
    {
        if (Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO] == null)
        {
            Script.RedirectNewUrl(url);
        }
        else
        {
            login = (PowerCreator.LMS.Web.DL.User.LoginEntity)Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO];
            if (login == null)
            {
                Script.RedirectNewUrl(url);
            }
            else
            {
                if (login.VOAdvancedUser == null)
                {
                    Script.RedirectNewUrl(url);
                }
                else if (login.VOAdvancedUser.AUserGroup != 1)
                {
                    //Response.Write(login.VOAdvancedUser.AUserGroup.ToString());
                    //Response.End();
                    Script.ShowAndHistory("您无此权限！", -1);
                }
            }
        }


    }
    protected override void InitPage()
    {
        lbl_InfoTitle.Text = GetLanageValueByKey("lbl_AddDuty_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_DutyName.Text = GetLanageValueByKey("lbl_AddDuty_DutyName", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_DutyDesc.Text = GetLanageValueByKey("lbl_AddDuty_DutyDesc", PowerCreator.LMS.Language.LanagetItemType.Page);


        btnSave.Text = GetLanageValueByKey("btn_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnReset.Text = GetLanageValueByKey("btn_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!CheckDuty()) return;

        VOTTeacherDuty vo = new VOTTeacherDuty();
        vo.TeadutyDescription = txt_Description.Text;
        vo.TeadutyName = txt_DutyName.Text;
        if (opDuty.Add(vo))
        {
            string url = "DutyManager.aspx";
            Script.RedirectURL(url);
        }
    }

    private bool CheckDuty()
    {
        string search = string.Format("TeadutyName = '{0}'", txt_DutyName.Text);
        if (opDuty.Count(search) != 0)
        {
            lbl_msg_description.Text = GetLanageValueByKey("lbl_msg_addjob_aspx_count", PowerCreator.LMS.Language.LanagetItemType.MSG);
            txt_DutyName.Text = "";
            return false;
        }
        if (txt_Description.Text.Length > 200)
        {
            lbl_msg_description.Text = GetLanageValueByKey("lbl_msg_addjob_aspx_max", PowerCreator.LMS.Language.LanagetItemType.MSG);
            return false;
        }
        return true;
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        string url = "DutyManager.aspx";
        Script.RedirectURL(url);
    }
}
